import java.util.*;

public class test {
    public static void main(String[] args) {
        TreeSet<String> set = new TreeSet<>();

        set.add("shaniao");
        set.add("吃大便");
        set.add("hello");
        set.add("wht");

        Object[] s =  set.toArray();//将set元素转换为数组
        for (Object e:
             s) {
            System.out.print(e + " ");
        }
        System.out.println();

        List<String> list1 = new ArrayList<>();
        list1.add("吃大便");
        list1.add("hello");
        List<String> list2 = new ArrayList<>();
        list2.add("吃大便");
        list2.add("shaiscjsdbvjdbvidfknbodfbnd");
        List<String> list3 = new ArrayList<>();//空数组
        System.out.println("list1:"+set.containsAll(list1));
        System.out.println("list2:"+set.containsAll(list2));
        System.out.println("list3:"+set.containsAll(list3));
        List<String>  list4 = new LinkedList<>();
        list4.add("wht");
        list4.add("shaniao");
        System.out.println("list4:"+set.containsAll(list4));

        set.addAll(list2);
        System.out.println(set);

    }
    public static void main7(String[] args) {
        TreeSet<String> set = new TreeSet<>();

        System.out.println("是否为空" + set.isEmpty());
        System.out.println("当前size:"+set.size());
        set.add("shaniao");
        set.add("shaniao");
        set.add("hello");
        set.add("wht");
        //迭代器
        Iterator<String> it = set.iterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();

        System.out.println("是否为空" + set.isEmpty());
        System.out.println("当前size:"+set.size());

        System.out.println(set.remove("hello"));
        System.out.println(set.remove("qwrey"));
        System.out.println("当前size:"+set.size());

        set.clear();
        System.out.println("是否为空" + set.isEmpty());
        System.out.println("当前size:"+set.size());
    }
    public static void main6(String[] args) {
        TreeMap<String, Integer> map = new TreeMap<>();
        map.put("Hello", 2);
        map.put("linux", 6);
        map.put("world", 1);
        map.put("world", 6);

        Set<String> set =  map.keySet();//返回所有不重复的key的集合
        System.out.println(set);

        Collection<Integer> num = map.values();//返回所有value可重复集合
        for (Integer e:
             num) {
            System.out.print(e + " ");
        }
        System.out.println();

        //返回所有key——value映射关系
        Set<Map.Entry<String,Integer>> set1 = map.entrySet();
        //System.out.println(set1);
        for (Map.Entry<String,Integer> e:
             set1) {
            System.out.println("key:" + e.getKey() + " value:" + e.getValue());
        }
        System.out.println();
    }
    public static void main5(String[] args) {
        TreeMap<String, Integer> map = new TreeMap<>();
        map.put("Hello", 2);
        map.put("linux", 6);
        map.put("world", 1);
        //判断是否存在key 和 判断是否存在value 的方法
        System.out.println(map.containsKey("heool"));
        System.out.println(map.containsKey("Hello"));

        System.out.println(map.containsValue(6));
        System.out.println(map.containsValue(100));
    }
    public static void main4(String[] args) {
        TreeMap<String, Integer> map = new TreeMap<>();
        map.put("Hello", 2);
        map.put("linux", 6);
        map.put("world", 1);

        //remove方法
        map.remove("Hello");
    }
    public static void main3(String[] args) {
        TreeMap<String, Integer> map = new TreeMap<>();
        map.put("Hello", 2);
        map.put("linux", 6);
        map.put("world", 1);

        //get方法 和 getOrDefault方法
        System.out.println(map.get("Hello"));
        System.out.println(map.get("shaniao"));
        System.out.println(map.getOrDefault("Hello", 666));
        System.out.println(map.getOrDefault("chunhuo", 654));
    }
    public static void main2(String[] args) {
        TreeMap<String,Integer> map = new TreeMap<>();
        //put方法
        map.put("WHT",1);
        map.put("Liuzhong",250);
        map.put("shaniao",2);
        map.put("world",6);
        map.put("world",25);//key值不应该重复，重复的话value值会更新

        //返回值规则：键不存在时：将新键值对插入 Map，返回 null（表示无旧值）键存在时：用新值覆盖旧值，返回被替换的旧值
        System.out.println(map.put("WHT", 666));
        System.out.println(map.put("chiniuzi",1));


    }

    public static void main1(String[] args) {
        BinarySearchTree bst = new BinarySearchTree();
        bst.insert(10);
        bst.insert(5);
        bst.insert(15);
        bst.insert(16);
        bst.insert(3);
        bst.insert(18);

        BinarySearchTree.Treenode ret = bst.search(15);
        System.out.println(ret.val);


    }
}
